home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-03 | 9.4 KB | 342 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: Frame.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "AMSample.hpp"
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- gadgets -----
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef RECTVIEW_H
- #include "RectView.h"
- #endif
-
- #ifndef PICTVIEW_H
- #include "PictView.h"
- #endif
-
- #ifndef FWLISTBX_H
- #include "FWListBx.h"
- #endif
-
- #ifndef FWCLUSTR_H
- #include "FWClustr.h"
- #endif
-
- #ifndef FWBUTTON_H
- #include "FWButton.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- // ----- Graphic Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment AMSample
- #endif
-
- FW_DEFINE_AUTO(CAMSampleFrame)
- FW_DEFINE_CLASS_M2(CAMSampleFrame, FW_CFrame, FW_MReceiver)
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame constructor
- //----------------------------------------------------------------------------------------
- CAMSampleFrame::CAMSampleFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CAMSampleContent* content)
- : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
- FW_MDraggableFrame(ev, this),
- FW_MDroppableFrame(ev, this),
- fAMSampleContent(content)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame destructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleFrame::~CAMSampleFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CAMSampleFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult acceptDrop = FW_MDroppableFrame::CanAcceptDrop(ev, dragInfo);
-
- // ----- Test for 'TEXT' also -----
- #ifdef FW_BUILD_MAC
- if (!acceptDrop)
- {
- for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0)) // 'TEXT' on Scrap
- return TRUE;
- }
- #endif
-
- return acceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CAMSampleFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean result = FALSE;
-
- if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
- {
- result = this->Drag(ev, theMouseEvent);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CAMSampleFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean menuHandled = TRUE;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- switch (id)
- {
- default:
- menuHandled = FALSE;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CAMSampleFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- if (hasMenuFocus)
- {
- //---- Set up the Edit menu items ----
- #ifdef FW_BUILD_MAC
- menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
- #endif
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CAMSampleFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape) // Override
- {
- FW_CViewContext gc (ev, this, odFacet, invalidShape);
-
- // fill with background color
- FW_CInk fillInk (FW_CColor (255, 255, 255)); // white
- FW_CRect bounds = this->GetBounds(ev);
- FW_CRectShape::RenderRect (gc, bounds, FW_kFill, fillInk);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- // By default a FW_CFrame view is not refreshed entirely when resized.
- // You must decide if your content's appearance depends on the frame's size.
- // If it doesn't you don't need to override FrameShapeChanged().
- // Here we must redraw the whole frame everytime because the text is centered.
-
- void CAMSampleFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CAMSampleFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- return FW_NEW(CAMSampleEditCommand, (ev, commandID, fAMSampleContent, this));
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CAMSampleFrame::NewDragCommand(Environment *ev,
- FW_CFrame* theFrame,
- const FW_CMouseEvent& theMouseEvent)
- {
- return FW_NEW(CAMSampleDragCommand, (ev, fAMSampleContent, theFrame));
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CAMSampleFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- return FW_NEW(CAMSampleDropCommand, (ev, fAMSampleContent, this, dropInfo, odFacet, dropPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void CAMSampleFrame::CreateSubViews(Environment* ev)
- {
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- // Use the macro FW_DO_NOT_DEAD_STRIP for those classes which are not
- // referenced anywhere else in your part's code.
- FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
- FW_DO_NOT_DEAD_STRIP(CContentView);
-
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(CRectView);
- FW_DO_NOT_DEAD_STRIP(CPictView);
- FW_DO_NOT_DEAD_STRIP(FW_CListBox);
- FW_DO_NOT_DEAD_STRIP(CRadioGroup);
- FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
- FW_DO_NOT_DEAD_STRIP(FW_CStaticText);
-
- CreateSubViewsFromResource(ev, kMainWindowResID);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleFrame::HandleNotification
- //----------------------------------------------------------------------------------------
-
- void CAMSampleFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
- {
- // Handle notification messages for the registered controls.
- // GetMessage() allows to switch on the type of notification. For each message
- // we can down-cast "notification" directly to the right subclass, without
- // having to use RTTI, because the message is unique to that type.
-
- switch (notification.GetMessage())
- {
- default:
- FW_ASSERT("CAMSampleFrame can't respond to this");
- break;
- }
- }
-